O-CPS SPEC

Если бы O-CPS был PhD :-)

1. Синтаксис. Модифицированный lalrpop (убраны типы-аттрибуты и несущественные элементы, отсутствуют терминалы, можно найти в предыдущих постах).

E: V | A | C NC: ";" = [] | ";" m:NL = m FC: ";" = [] | ";" m:FL = m EC: ";" = [] | ";" m:EL = m NL: NAME | o:NAME m:NC = Cons o m FL: E | o:E | m:FC = Cons o m EL: E | EC | o:E m:EC = Cons o m V: v:V = Verb v [] [] | v:V r:E = Verb v [] r A: a:A = Adverb a [] [] | v:A r:E = Adverb v [] r C: N | c:N a:C = Call c a | l:N a:A = Adverb a l [] | l:N v:V = Verb v l [] | l:N a:A r:E = Adverb a l r | l:N v:V r:E = Verb v l r N: NAME | S | HEX | L | D | F D: "[" "]" = [] | "[" l:EL "]" = Dict l L: "(" ")" = [] | "([" c:NL "]" m:FL ")" = Table c m | "(" l:EL ")" = List l F: "{" "}" = Lambda [] [] [] | "{[" c:NL "]" m:EL "}" = Lambda [] c m | "{" m:EL "}" = Lambda [] [] m

2. Порт Rust в System F (убраны лайфтаймы).

lazy n (Assign n b) e k = D n b (ContAssign n k) n (Cond v a l) e k = D n v (ContCond l r k) n (List l) e k = eve n l e k n (Call c a) e k = D n a (ContCall c k) n (Verb v (Number _) r) e k = D n r (ContVerb v l 0 k) n (Verb v _ (Number _)) e k = D n v (ContVerb v r 1 k) n (Verb v x y) e k = D n x (ContVerb v y 0 k) n (Name s) e k = cont (lookup n s e) k n (Lambda _ x y) e k = cont ((Lambda n x y) n) k evf n (Lambda c x y) a e k = cont (y (if (= c []) n c)) (ContFunc x a k) n (Name s) a e k = lookup n s e eve n (Cons a d) e k = D n a (ContExpr d k) n Nil e k = cont n Nil e k n a e k = D n a k emr (Dict x) e k = R Dict (rev x) (Cons x y) e k = R Dict (Cons (rev x) (rev x)) a e k = R a run D n a e k = lazy n a e k R a = a cont n (Dict v) e (ContCall c k) = evf n c v e k n x e (ContCall c k) = evf n c x e k n x e (ContFunc s a k) = eve (e.define_args s (rev a)) v k n False e (ContCond l r k) = D n r k n True e (ContCond l r k) = D n l k n x e (ContCond l r k) = D n x (ContCond l r k) n x e (ContAssign (Name s) k) = eve n (e.define s x) k n x e (ContExpr (Cons a d) k) = eve n (Cons a d) k n x e (ContExpr r k) = cont n x k n x e ContRet = emr x e k